package thread;

public class ThreadDemo11 {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
             for (int i = 0; i < 3; i++) {
                 System.out.println("hello thread");
                 try {
                     Thread.sleep(1000);
                 } catch (InterruptedException e) {
                     e.printStackTrace();
                     break;
                 }
             }
        });
        thread.start();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("join之前");

        //此处的join就是让当前的main线程来等待thread线程指向结束（等待thread的run执行完）
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("join 之后");
    }
}
